package session

import (
	"github.com/kataras/iris"
	"github.com/kataras/iris/sessions"
)

var (
	cookieNameForSessionID = "mycookiesessionnameid"
	sess                   = sessions.New(sessions.Config{Cookie: cookieNameForSessionID})
)
func Secret(ctx iris.Context) {
	//验证用户授权
	if auth, _ := sess.Start(ctx).GetBoolean("authenticated"); !auth {
		ctx.StatusCode(iris.StatusForbidden)
		return
	}
	//输出消息
	ctx.WriteString("The cake is a lie!")
}
//使用登录操纵后服务保存session
func Login(ctx iris.Context) string{
	 session := sess.Start(ctx)
	 id :=session.ID()
	 //fmt.Println(id)
	 session.Set("authenticated", true)
	 return id
}
func Logout(ctx iris.Context) {
	session := sess.Start(ctx)
	// 撤消用户身份验证
	session.Set("authenticated", false)
}
